package com.dxj.response;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dxj
 * @Description 分页结果
 * @date 2024/7/31 13:34
 */
@Data
public class PageResultVo<T> {
    /**
     * 数据总量
     */
    private Long total;
    /**
     * 记录数
     */
    private List<T> records;

    public PageResultVo(){
        this.records = new ArrayList<>();
    }

    public PageResultVo(Long total, List<T> records) {
        this.total = total;
        if (records == null) {
            this.records = new ArrayList<>();
        } else {
            // 防御性拷贝，避免外部修改
            this.records = new ArrayList<>(records);
        }
    }

    public PageResultVo(Long total){
        this.total=total;
        this.records=new ArrayList<>();
    }
    public static <T> PageResultVo<T> empty() {
        return new PageResultVo<>(0L);
    }

    public static <T> PageResultVo<T> empty(Long total) {
        return new PageResultVo<>(total);
    }
}
